import { password } from "../../../../js/modules/account.js";
const info = require("../../../../js/modules/info.js");
import { forms, storage, util } from '../../../../js/util';
import {
  router
} from '../../../../js/router';
import authorize from '../../../../js/modules/authorize.js'
import BasePage from '../../../../js/common/base-page'
import { setStorageSync } from "../../../../js/compatible.js";
import { deepClone } from "../../../../js/newUtil.js";
const app = getApp()
BasePage({
  pageKey:"payPwdModify",

  /**
   * 页面的初始数据
   */
  data: {
    forms: {
      LoginPwd: {
        value: "",
        validate: "isnull",
        error: "请输入登录密码"
      },
      OldPassword: {
        value: "",
        validate: "isnull",
        error: "请输入旧支付密码"
      },
      PicVerifyCode: {
        value: "",
        validate: "isnull",
        error: "请输入正确的校验码"
      },
      Password: {
        value: "",
        validate: "isnull|pwd",
        error: "请输入正确的新支付密码"
      },
      RepPassword: {
        value: "",
        validate: "isnull|pwd",
        error: "请输入正确的新支付确认密码"
      },
    },
    editType: '', // 修改密码时的类型， resetDefaultPassword（修改默认密码）
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.editType == 'resetDefaultPassword') { // 进入页面为修改默认密码
      this.setData({
        editType: 'resetDefaultPassword'
      })
    }
    //获得图片验证码组件
    this.picVerifyCode = this.selectComponent("#PicVerifyCode");
    //设置回调
    this.picVerifyCode.data.callback = info.getPicVerifyCode;
    //调用一次图片验证码
    this.picVerifyCode.bindPicVerifyCode();
  },
  /**
       * 表单值绑定
       */
  bindFormValue: function (e) {
    e = e.detail;
    this.data.forms[e.target.id].value = e.detail.value;

  },
  /**
   * 
   */
  onSubmitEvent: function (e) {
    let that = this;
    let {
      forms,
      editType
    } = this.data
    forms = deepClone(forms)
    if (editType == 'resetDefaultPassword') {
      forms.LoginPwd.validate = undefined // 修改初始密码时，不校验登录密码（不需要填写密码）
      forms.OldPassword.value = '000000' // 默认初始密码
    }
    password.update_pay_pwd("store",forms,function(){
      util.alert("修改支付密码成功！", "提示", function () {
        that.goBack();
      });
    });

  },
  /**
   * 取消
   */
  onCancelEvent: function (e) {

    this.goBack();
  },
  /**
   * 返回上页面
   */
  goBack(){
    var pages = getCurrentPages();
    //获取上一个页面的所有的方法和data中的数据
    var lastpage = pages[pages.length - 2];
    if (lastpage.route.indexOf("index") > 0) {
      setStorageSync('tabindex', app.dns.centerNum);
      router.switchTab({
        path: "center"
      });
    }
    else {
      router.navigateBack({
        path: lastpage.route
      },true);
    }
  },
  /**
   * 找回支付密码
   */
  onFindPayPwdEvent:function(e){
    var params = {
      path: "findPayPwd"
    };
    router.navigate(params);
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})